package com.hxkj.service.impl;

import com.hxkj.dao.ContentDao;
import com.hxkj.domain.po.Content;
import com.hxkj.service.ContentService;
import com.platform.common.domain.result.ResultDataStruct;
import com.platform.common.domain.result.ResultMessageStruct;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName ContentServiceImpl
 * @Description TODO
 * @Author Mr.zheng
 * @Date 2018/9/9 14:44
 * @Version 1.0
 */
@Service
@Slf4j
public class ContentServiceImpl implements ContentService {

    @Autowired
    private ContentDao contentDao;

    @Override
    public ResultDataStruct<Content> getContent(Content content) throws Exception {
        ResultDataStruct<Content> resultDataStruct = new ResultDataStruct<>();
        try {
            List<Content> contentList = contentDao.getContent(content);
            if (contentList != null && contentList.size() > 0) {
                resultDataStruct.setData(contentList.get(0));
                resultDataStruct.setCode(200);
                return resultDataStruct;
            }
            resultDataStruct.setCode(401);
        } catch (Exception e) {
            e.printStackTrace();
            resultDataStruct.setCode(401);
            resultDataStruct.setMessage(e.getMessage());
        }
        return resultDataStruct;
    }

    @Override
    public ResultMessageStruct saveContent(Content content) {
        ResultMessageStruct resultMessageStruct = new ResultMessageStruct();
        try {
            int i = contentDao.saveContent(content);
            if (i == 0) {
                resultMessageStruct.setCode(401);
                resultMessageStruct.setMessage("映射内容添加失败");
                return resultMessageStruct;
            }
            resultMessageStruct.setCode(200);
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
        return resultMessageStruct;
    }
}
